//
//  CZDiscoverSeachView.swift
//  WHWeiBo01
//
//  Created by 炜张 on 16/7/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZDiscoverSeachView: UIView,UITextFieldDelegate {

    @IBOutlet weak var rightTextFiled: NSLayoutConstraint!
    
    @IBOutlet weak var textfiled: UITextField!
    
    @IBOutlet weak var cancelButton: UIButton!
    
    //加载XIB
    class func searchView() -> CZDiscoverSeachView {
        return UINib(nibName: "CZDiscoverSeachView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! CZDiscoverSeachView
    }
    
    
    @IBAction func cancelAction(sender: AnyObject) {
        //取消第一响应
//        self.endEditing(true)
        textfiled.resignFirstResponder()
        //右边间距设置0
        rightTextFiled.constant = 0
        
        UIView.animateWithDuration(0.5) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    func textFieldDidBeginEditing(textField: UITextField) {
        rightTextFiled.constant = cancelButton.width
        UIView.animateWithDuration(0.5) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    
}














